import axios from 'axios'
import { ElMessage } from 'element-plus'

const server = axios.create({
    baseURL: '/dev-api',
    // baseUrl: import.meta.env.VITE_APP_BASE_API,
    timeout: 5000
})
console.log('请求的baseUrl:', process.env.VITE_APP_BASE_API,)
// 请求拦截
server.interceptors.request.use(config => {

    console.log('请求拦截', config)
    return config
}, error => {
    console.log('请求拦截错误', error)
    return Promise.reject(error)
})


// 响应拦截
server.interceptors.response.use(res => {

    console.log('响应拦截', res.data)
    const { code = '', msg = "" } = res.data
    console.log("验证码", msg)
    if (code != 200) {
        ElMessage.error({
            message: msg,
            type: 'error'
        })
        return Promise.reject(msg)
    }
    return res.data
}, error => {
    console.log("错误响应拦截", error)
    return Promise.reject(error)
})


export default server